package com.xmg.myautowired;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

public class DependencyResolutionDemo {
    @MyAutoWired
    private User user;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

        context.register(DependencyResolutionDemo.class);

        context.refresh();

        DependencyResolutionDemo bean = context.getBean(DependencyResolutionDemo.class);
        System.out.println(bean.user);

        context.close();
    }

    @Bean
    public User user() {
        User user = new User();
        user.setId(2);
        user.setName("xmg");
        return user;
    }


    @Bean
    public static AutowiredAnnotationBeanPostProcessor beanPostProcessor() {
        AutowiredAnnotationBeanPostProcessor postProcessor = new AutowiredAnnotationBeanPostProcessor();
        postProcessor.setAutowiredAnnotationType(MyAutoWired.class);
        return postProcessor;
    }
}
